fix(mysql): render TINYINT(1) columns as boolean in SQL Lab and charts - #35297
Closed
sadpandajoe wants to merge 2 commits into
Closed
sadpandajoe wants to merge 2 commits into
sadpandajoe wants to merge 2 commits into
Conversation
Fixes MySQL TINYINT(1)/BOOLEAN columns displaying as numeric icons with 0/1 values instead of boolean representation with True/False in SQL Lab and Explore views. ## Changes ### Schema Mapping (mysql.py) - Add precise column_type_mappings for TINYINT(1), BOOLEAN, and BOOL patterns - Map to GenericDataType.BOOLEAN for proper metadata inspection - Ensures dataset schemas show boolean icons for actual boolean types only ### Runtime Conversion (mysql.py) - Implement fetch_data override with ultra-precise boolean detection - Convert 0/1 integers to True/False for TINYINT(1) columns - Use multiple reliable markers: FIELD_TYPE.TINY + display_size=1 OR SQLAlchemy type string - Extract _is_boolean_column helper method for clean detection logic - Enables pandas boolean dtype inference via extract_dataframe_dtypes ### Testing (test_mysql.py) - Add boolean type test cases to existing parametrized tests - Test TINYINT(1), BOOLEAN, BOOL → boolean mapping - Test TINYINT, TINYINT(2+) → numeric mapping (preserved behavior) ## Technical Details MySQL stores BOOLEAN as TINYINT(1) but returns 0/1 integers instead of Python booleans. This two-layer solution: 1. Maps TINYINT(1) metadata to GenericDataType.BOOLEAN for schema inspection 2. Converts query result values 0/1 → True/False for proper pandas inference The detection uses explicit width 1 or positive SQLAlchemy type string markers to avoid mis-converting broader TINYINT columns. Fixes: #35166 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…ersion
- Fix critical bug where bool('0') and bool(b'0') returned True instead of False
- Add proper type normalization for strings, bytes, and Decimal values
- Convert string/bytes/Decimal to int before applying bool() for accurate MySQL boolean conversion
- Maintains existing behavior for integer values while fixing edge cases
- Addresses feedback on conversion logic in mysql.py:323-330
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
| Category | Issue | Status |
|---|---|---|
| Unreliable boolean column detection across drivers ▹ view | 🧠 Not in standard |
Files scanned
| File Path | Reviewed |
|---|---|
| superset/db_engine_specs/mysql.py | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
Comment on lines
+289
to
+292
| # Check SQLAlchemy type string (some drivers provide it at index 4) | ||
| if len(col_desc) > 4 and isinstance(col_desc[4], str): | ||
| sqla_type_str = col_desc[4].lower() | ||
| return any(marker in sqla_type_str for marker in ["bool", "tinyint(1)"]) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| value = int(value) | ||
| elif isinstance(value, Decimal): | ||
| value = int(value) | ||
| new_row[col_idx] = bool(value) |
Member
There was a problem hiding this comment.
I think this is a perfect case for column_type_mutators, see https://github.com/apache/superset/blob/master/superset/db_engine_specs/base.py#L342-L344 and https://github.com/apache/superset/blob/master/superset/db_engine_specs/base.py#L993-L998
Member
Author
|
closing for now as it's pretty stale. will work on it again later if priorities change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SUMMARY
Root Cause
MySQL boolean fields were incorrectly displaying as numeric icons with raw 0/1 values instead of readable True/False text in SQL Lab and Explore views. The issue had two layers:
Solution
Two-layer fix targeting MySQL's TINYINT(1) boolean representation:
Changes
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION